<?php
/**
 * Created by gumaor.com
 * User: tommy
 */

namespace lib;


class Format
{
    /**
     * 格式化为key value的hash模式
     *
     * @param $key_name
     * @param $value_name
     * @param $data
     * @return array
     */
    public static function hash($key_name, $value_name, &$data)
    {
        $hash = [];
        if (empty($data)) {
            return $hash;
        }
        foreach ($data as $row) {
            if (!empty($value_name)) {
                $hash[$row[$key_name]] = $row[$value_name];
            } else {
                $key = $row[$key_name];
                unset($row[$key_name]);
                $hash[$key] = $row;
            }
        }
        return $hash;
    }

    /**
     * 格式化星期
     *
     * @param $time
     * @return mixed|string
     */
    public static function weekday($time)
    {
        if (is_numeric($time)) {
            $weekday = array('周日', '周一', '周二', '周三', '周四', '周五', '周六');
            return $weekday[date('w', $time)];
        }
        return '';
    }
}
